//index.js
//获取应用实例
const app = getApp()
const Api = require("../../utils/api.js").API
const Store = require("../../utils/store.js").store
const codeZ = require("../../utils/util.js")
var WxParse = require('../../wxParse/wxParse.js');
Page({
    data: {
      
        showXin: false,
        showfu:false,

        
    },
    onLoad: function(options) {
         let that = this;
       
        console.log(options);
            // options={'custNo':"sku10834406843392",'item':'sku10834406843392'};
        if (options.hasOwnProperty('custNo')) {
            // bean = {'evNo':optins.item};//测评详情
            // let a = optins.item;
            app.globalData.custNo = options.custNo;
            this.setData({
                wode: options.item,
                custNo: options.custNo,
            })

            Api.getGoodsDetailApi({
                'skuNo': options.item
            }).then(res => {
                if (res.code == 0) {
                    var a = res.data.goodsIntroduce;
                    if (a != null) {     
                        　 WxParse.wxParse('article', 'html',a, that, 5);

                    }
                    that.setData({
                        goods: res.data,
                       
                       
                    })
                    
                }
            })


        } else {




            var bean = {};
            const eventChannel = this.getOpenerEventChannel()
            eventChannel.on('acceptDataFromOpenerPage', function(data) {

                bean = data.data;
                that.setData({
                    wode: data.data.skuNo,
                })
                Api.getGoodsDetailApi({
                    'skuNo': bean.skuNo
                }).then(res => {
                    if (res.code == 0) {
                        var a = res.data.goodsIntroduce;
                        if (a != null) {
　 WxParse.wxParse('article', 'html',a, that, 5);
                        }
                        that.setData({
                            goods: res.data,
                           
                        })
                    }
                })

            })
        }

    },
    onShow() {
        let myCust = wx.getStorageSync('myCustNo');
        if (myCust.length > 5) {
            this.setData({
                showShre: true
            });

            // return  wx.showToast({ title: "请先登录！", icon: 'none' });
        } else {
            this.setData({
                showShre: false
            });
        }
        var shre = wx.getStorageSync('share');

        if (shre != null && shre == 'share') {
            this.setData({
                show: true
            });
        }
    },
    shareNo() {
       
            
        wx.navigateTo({
            url:'../login/index'
        })
        
        // wx.showToast({
        //     title: '请先登录再进行分享',
        //     icon: 'none'
        // });
    },
    sure() {
        wx.setStorageSync("share", "")
        this.setData({
            show: false
        });
    },
    onShareAppMessage: function() {
        var that = this;
        // let url = encodeURIComponent('pages/DetailData/index');
        Api.ByShareApi().then(res => {
            if (res.code == 0 && res.data != null) {
                if (res.data.length != 0) {
                    wx.setStorageSync("share", "share");
                    that.setData({
                        sum: res.data.length
                    })
                }
            }
        })
        let a = this.data.wode;
        let cust = wx.getStorageSync('myCustNo');
        return {

            title: "商品信息",
            path: `/pages/index/index?source=shopPage&sence=` + a + `&custNo=` + cust,
            success: function(res) {
                // 转发成功之后的回调
                if (res.errMsg == 'shareAppMessage:ok') {}
            }
        }
    },


    goBill: function() {
        if(this.data.showShre){
            var str = this.data.goods;
            if(str.saleGiftCard == '103101'){
                
                return this.setData({
                    showCarid:true,
                     itemZhi:str,
                    
                })
            }
            
            
            wx.navigateTo({
                url: '../shouliren/index',
                success: function(res) {
                    // 通过eventChannel向被打开页面传送数据
                    res.eventChannel.emit('acceptDataFromOpenerPage', {
                        data: str,type:'111801'
                    })
                }
            })
            
        }else{
            wx.navigateTo({
                url: '../login/index',
              
            })
            
             // wx.showToast({ title: "请先登录！", icon: 'none' });
        }
      


    },
    
    onClose() {
           this.setData({ showCarid: false });
         },
       
         onSelect(event) {
             let ite = this.data.goods;
            
           let a =event.detail.name;
           if(a == '购买礼品卡'){
              
    wx.navigateTo({
             url: '../shouliren/index',
               success: function(res) {
                 // 通过eventChannel向被打开页面传送数据
                 res.eventChannel.emit('acceptDataFromOpenerPage', { data:ite,type:'111802' })
               }
       })
             
           }else{
               
      wx.navigateTo({
               url: '../shouliren/index',
                 success: function(res) {
                   // 通过eventChannel向被打开页面传送数据
                   res.eventChannel.emit('acceptDataFromOpenerPage', { data:ite,type:'111801'})
                 }
         })
               
           }
         },



    jumpG: function() {
        wx.switchTab({
            url: '../cart/index',
        })
    },
    clickSC: function() {
         if(!this.data.showShre){
         return    wx.navigateTo({
                 url:'../login/index'
             })
           }
        
        let that = this;
        var boll = this.data.goods;
        if (boll.clNo != null) {
            Api.deleSCApi(boll.skuNo).then(res => {
                if (res.code == 0) {
                    that.setData({
                        ['goods.clNo']: null
                    })
                }
            })

        } else {
            let data = {
                "goodsNo": this.data.goods.goodsNo,
                "skuNo": this.data.goods.skuNo
            }
            Api.saveSCApi(data).then(res => {
                if (res.code == 0) {
                    that.setData({
                        ['goods.clNo']: 1
                    })
                }

            })

        }
    }

    ,
    shareMai:function(){
        this.setData({
            showXin:true,
        })
    
    },    
    addHj:function(){
        this.setData({
            show:true
        })
        
    },
    onClose:function(){
        this.setData({
            show:false,
            showXin:false,
        })
    },
    clickSelectGuoge:function(e){
        this.setData({
            selectZhi:e.currentTarget.dataset.index
        })
        
    },
    
    clickTap:function(){
        wx.navigateTo({
            url:'../faQuan/index'
        })
        
    },
     onChange(event) {
        // event.detail 为当前输入的值
        console.log(event.detail);
      },
    userNameInput:function(e){
        console.log(e);
        this.setData({
          amt:e.detail.value
        })
      },
      
      onClose:function(){
          this.setData({
             showfu:false,
              showXin:false,
          })
      },
      jump:function(){
          this.setData({
              showXin:true,
          })
      },
      jumpFu:function(){
          this.setData({
              showfu:true,
              
          })
      }

})
